<template>
  <div>
    <!-- 1.产品搜索 -->
    <div class="header">
      <div class="form">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="产品名称">
            <el-input v-model="formInline.name" placeholder="产品名称"></el-input>
          </el-form-item>

          <el-form-item label="添加时间">
            <el-date-picker v-model="formInline.data" type="date" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="group">
        <el-button size="small" type="warning" icon="el-icon-edit" @click="toProductPage">添加商品</el-button>
        <el-button size="small" type="danger" icon="el-icon-delete">批量删除</el-button>
      </div>
    </div>
    <!-- 2.产品列表 -->
    <div class="container">
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column label="日期时间" width="180">
          <template slot-scope="scope">
            <span>{{ moment(scope.row.create_time).format('YYYY-MM-DD HH:mm:ss') }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="descs" label="商品描述" width="180">
          <template slot="scope">
            <span>{{ removeHTMLTag(scope.row.descs) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="地址">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import moment from 'moment';
import {removeHTMLTag} from '@/utils/common.js'
export default {
  name: 'listIndex',
  data() {
    return {
      // 产品搜索
      formInline: {
        name: '',
        data: ''
      },
      // 产品列表
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }]
    }
  },
  methods: {
    removeHTMLTag,
    moment,
    onSubmit() {
      console.log('submit!');
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    toProductPage(){
      this.$router.push('/product/productpage')
    }
  }
}
</script>

<style lang="less" scoped>
.header {
  background-color: #fff;
}

.container {
  background-color: pink;
}
</style>